(function() {

  /////////////////////////////// home hero parallax slider functions ///////////////////
  var iphoneSwiper = new Swiper('#carousel-iphone', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    autoplay: 4000,
    direction: 'horizontal',
    spaceBetween: 0,
    autoplayDisableOnInteraction: false
  });

  var macbookSwiper = new Swiper('#carousel-macbook', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    autoplay: 4000,
    direction: 'horizontal',
    spaceBetween: 0,
    autoplayDisableOnInteraction: false
  });

  macbookSwiper.on('slideChangeStart', function() {
    if (macbookSwiper.activeIndex == 0) {
      $('#title_1').removeClass('hidden');
      $('#subtitle_1').removeClass('hidden');

      $('#title_2').addClass('hidden');
      $('#subtitle_2').addClass('hidden');

      $('.slider-0').removeClass('hidden');
      iphoneSwiper.slidePrev();
    } else {
      $('#title_1').addClass('hidden');
      $('#subtitle_1').addClass('hidden');

      $('#title_2').removeClass('hidden');
      $('#subtitle_2').removeClass('hidden');
      iphoneSwiper.slideNext();
    }
  });

  iphoneSwiper.on('slideChangeStart', function(){
    if(iphoneSwiper.activeIndex==0){
      macbookSwiper.slidePrev();
    } else {
      macbookSwiper.slideNext();
    }
  });

  function apply4trail() {
    window.location.href = '/apply_for_trail.html';
  }
  /////////////////////////////// themes slider functions ///////////////////

  var showCase = new Swiper('#view-showcases .js-showcases-swiper', {
    autoplay: 5000,
    speed: 600,
    initialSlide: 3,
    loop: false,
    // loopAdditionalSlides: 3,
    autoplayDisableOnInteraction: false,
    centeredSlides: true,
    direction: 'horizontal',
    spaceBetween: 60,
    slidesPerView: 1,
    simulateTouch: false,
    noSwiping: true,
    prevButton:'.btn-swiper-prev',
    nextButton:'.btn-swiper-next',
    onTransitionStart: function(swiper) {
    },
    onTransitionEnd: function(swiper) {
    },
    breakpoints: {
      767: {
        initialSlide: 1,
        spaceBetween: 30,
        noSwiping: false,
        loop: true,
        autoplay: 5000
      }
    }
  });

    $('#view-showcases .js-showcases-swiper').on('click', '.swiper-slide.swiper-slide-prev', function() {
      showCase.slidePrev();
    });

    $('#view-showcases .js-showcases-swiper').on('click', '.swiper-slide.swiper-slide-next', function() {
      showCase.slideNext();
    });

    $('#view-showcases .js-showcases-swiper').on('mouseover', '.swiper-slide.swiper-slide-active', function() {
      showCase.stopAutoplay();
    });

    $('#view-showcases .js-showcases-swiper').on('mouseleave', '.swiper-slide.swiper-slide-active', function() {
      showCase.startAutoplay();
    });

  //////////////////////////////// testimonials ////////////////////////////////
  var swiperSingle = new Swiper('#view-testimonials .swiper-container', {
    direction: 'horizontal',
    loop: true,
    nextButton: '.swiper-button-next',
    prevButton: '.swiper-button-prev'
  })
  var swiperThree = new Swiper('#view-testimonials .swiper-container-three', {
    direction: 'horizontal',
    slidesPerView: 2,
    loop: true,
    nextButton: '.swiper-button-next-lg',
    prevButton: '.swiper-button-prev-lg',
    onInit: function(swiper) {
      HeyShop.fillImages($('#view-testimonials .swiper-slide-duplicate'));
    },
    breakpoints: {
      767: {
        slidesPerView: 1
      }
    }
  })

  /////////////////////////////// video in home slide //////////////////////////
  // var video = $('#view-hero .video')[0];
  // $('#view-hero .video')[0].addEventListener('ended', function() {
  //   video.pause();
  //   $('#play-pause').removeClass('playing');
  //   $('#carousel-home-hero').carousel('pause')
  // }, false);

  // $('#view-hero #video-controls').off('click').click(function() {
  //   if (video.paused) {
  //     video.play();
  //     $('#play-pause').addClass('playing');
  //     $('#carousel-home-hero').carousel('pause');
  //     showCase.stopAutoplay();
  //   } else {
  //     video.pause();
  //     $('#play-pause').removeClass('playing');
  //     $('#carousel-home-hero').carousel('cycle');
  //     showCase.startAutoplay();
  //   }
  // });


  // redirect to register page with email
  var $emailInput = $('#view-email input.subscribe-email-input[name=email]');
  $('#view-email .btn-subscribe').on('click', function() {
    var email = $emailInput.val();
    if (email) {
      window.location = `/register?email=${email}`
    }
  });

  var consoleTip = '%c                                               :::             \n';
  console.log(consoleTip, "color: red; font-size: 10px");

})(jQuery)
